package com.brkj.test;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import com.brkj.main.R;
import com.brkj.test.model.DS_Exam_detail_ques;
import com.brkj.util.ConstAnts;
import com.brkj.util.view.BaseActivity;
import com.brkj.util.view.PullListView;
import com.dgl.sdk.util.DBStore;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dgl on 2014/4/22.
 */
public class ExamWrongQuesActivity extends BaseActivity{
    private ListView listView;
    private TextView noData;
    private List<DS_Exam_detail_ques> wrongList = new ArrayList<DS_Exam_detail_ques>();
    private String examId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setAnimType(RIGHT_ENTER_LEFT_EXT);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.test_exam_wrong_ques_list);

        listView = (ListView) findViewById(R.id.listView);
        noData = (TextView) findViewById(R.id.noData);

        setReturnBtn();
        setActivityTitle("错题练习");

        examId = getIntent().getStringExtra("examID");

        fillView();

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(ExamWrongQuesActivity.this, ExamDetailWrongQuesActivity.class);
                intent.putExtra("examId", examId);
                intent.putExtra("postion", position);
                startActivityForResult(intent, 0);
            }
        });
    }

    private void fillView(){
        wrongList = DBStore.readAll(DS_Exam_detail_ques.class, ConstAnts.DB_TABLE_WRONGQUES+examId);

        if(wrongList.size() == 0){
            noData.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
        }else {
            noData.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);

            ExamWrongQuesAdapter adapter = new ExamWrongQuesAdapter(this, wrongList);

            listView.setAdapter(adapter);
        }

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        fillView();
    }
}
